<?php
/**
 * Created by PhpStorm.
 * User: 29620
 * Date: 2021/11/22
 * Time: 15:32
 */
namespace app\admin\model;

use think\Model;

class Goods extends Model
{
    
    //获取器
    public function getAddtimeZhAttr($v,$d) { return date('Y-m-d H:i:s',$d['addtime']); }
    public function getIsShowZhAttr($v,$d)  {   return $d['is_show']?'√.jpg':'X.jpg';   }
    public function getIsHotZhAttr($v,$d)    {   return $d['is_hot']?'√.jpg':'X.jpg';    }
    public function getIsDownZhAttr($v,$d)   {   return $d['is_down']?'√.jpg':'X.jpg';    }

    
    //搜索器
    public function searchKeywordsAttr($q,$v,$d) { $q->where('g.name','like',"%{$v}%");  }
    public function searchIsHotAttr($q,$v,$d)    { $q->where('g.is_hot','=',$v); }
    public function searchIsShowAttr($q,$v,$d) { $q->where('g.is_show','=',$v);  }
    public function searchIsDownAttr($q,$v,$d)    { $q->where('g.is_down','=',$v); }
    public function searchCidAttr($q,$v,$d)    { $q->where('g.cid','=',$v); }

    public function searchKTimeAttr($q,$v,$d)   {   $q->where('g.addtime','> TIME',$v); }
    public function searchJTimesAttr($q,$v,$d)  {   $q->where('g.addtime','< TIME',$v); }
    public function searchDPriceAttr($q,$v,$d)  {   $q->where('g.price','>',$v);    }
    public function searchGPriceAttr($q,$v,$d)  {   $q->where('g.price','<',$v);    }


    public static function getGoods($where,$param)
    {
        $list = Goods::alias('g')
            ->join('ecm_category c','g.cid=c.id')
            ->field('g.*')
            ->field('c.name as cname')
            ->withSearch(array_keys($where),$where)
            ->paginate(['list_rows' => 5,'query' => $param]);
        return $list;
    }
}
